<h1>Retournez un DVD </h1>
<?php

	if (!isAdminConnected()) die('vous n\'étes pas autorisé à voir cette page!');
	require I_PATH . 'xml.php';
	$bd = openBD();

	if(isset($_GET["idD"]) && isset($_GET["loginC"])){
		$stmt = $bd->prepare("DELETE FROM CLIENT_has_DVD WHERE idClient IN 
			(SELECT idClient FROM CLIENT WHERE login = :loginC) and idDvd = :idD");
		$stmt->bindParam(':loginC', $_GET["loginC"]);
		$stmt->bindParam(':idD', $_GET["idD"]);
		$count = $stmt->execute();
		
		if($count == 1){
			echo '<p class="ui-state-highlight">Le DVD à été rendu.</p>';
		}
	}

	$stmt = $bd->prepare("SELECT login, idDvd, date FROM CLIENT_has_DVD CD, CLIENT C WHERE C.idClient = CD.idClient");
	$stmt->execute();
	$stmt->setFetchMode(PDO::FETCH_ASSOC);
	
	echo "<table class='rounded-corner'>";
	echo "<tr>";
	echo "<th class='rounded-th-l'>Login de client</th>";
	echo "<th>Nom du DVD</th>";
	echo "<th>Date de location</th>";
	echo "<th class='rounded-th-r'>Remmettre le DVD</th>";
	echo "</tr>";
	while ($row = $stmt->fetch()) {
		$entries = $dvd_dom->getElementById($row["idDvd"]);
		$titre = $entries->getElementsByTagName("title");
		$titreV = null;
		foreach($titre as $e){
			$titreV = $e->nodeValue;
		}
		echo "<tr>";
		echo "<td>" . $row["login"] . "</td>";
		echo "<td>" . $titreV . "</td>";
		echo "<td>" . $row["date"] . "</td>";
		echo "<td class='center'><a href='?p=return&loginC=" . $row["login"] . "&idD=" . $row["idDvd"] . "'><span class=\"ui-icon ui-icon-check\"></span></a></td>";
		echo "</tr>";
    }
	echo "</table>";
?>